The CultureInfo class in ASP.NET

When it comes to localization of your application, especially a class is very important: the culture of the systemInfo class. Globalization Namespace From this class, you can find information about every possible culture there, which includes a wide range of culture-specific settings. Cultural Interface Class can really help you when your webpages are localized, especially Because ASP.NET will keep a reference for specific culture information related to a specific visitor. Does it look complicated? I'll show you a short example:


<%@ Page Language="C#" Culture="Auto" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CultureInfo demo</title>
</head>
<body>
    <form id="MainForm" runat="server">
        <% Response.Write("Your current culture: " + System.Globalization.CultureInfo.CurrentCulture.DisplayName);    %>
    </form>
</body>
</html>

Try to run it and get the culture related to you - but how? Actually, because the property of the page directive is set to Auto, it is controlled by your browser. Most browsers allow you to set your preferred languages, and since then, ASP.NET We try to find out which culture to use for you. We will see this later in more detail. Your current culture is used in many cases, for example, when formatting dates and numbers, because it differs from culture to culture. Now, you may want to use a specific culture, even if you What the Visitor Browser Tells You In that case, you can set the cultural property of the page in such a way:


<%@ Page Language="C#" Culture="en-US" %>

If you now run an example, you will be producing "English (United States)" with a specific American culture, which is the language of English. English also comes in other tastes, for example British or Australian N-US is considered a distinct culture, where N (English only) is considered a neutral culture, because it is only a language, specific to any country is not. Now, to see the difference between two cultures, try running this example:


<%@ Page Language="C#" Culture="en-US" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CultureInfo demo</title>
</head>
<body>
    <form id="MainForm" runat="server">
        <% Response.Write("Current date, in a culture specific format: " + DateTime.Now.ToString()); %>
    </form>
</body>
</html>

Now, try changing the page Culture to a German one, like this:


<%@ Page Language="C#" Culture="de-DE" %>

You will see the exact line of code output as a different result, because this culture is dependent but you can actually produce a cultural awareness date (or number or something) without changing the culture of the page, for example the way:


<% Response.Write("Current date, in a culture specific format: " + DateTime.Now.ToString(System.Globalization.CultureInfo.GetCultureInfo("de-DE").DateTimeFormat)); %>

We only get references to a German culture, and then use it as the parameter of the toasting () method on the date time class. The numbers also come with formform property for culture inforform numbers. Obviously, formatting dates and numbers is a small part of transferring an application, but Culture Info is the foundation of the orbit (or at least) this process, mainly because it is very well structured in the NAT framework Integrated with, and especially ASP NET

Culture vs. UICulture

It was about the property of culture, but the page class comes with any other related property: UIC culture property. The UI stands for User Interface, so in reality, this is the property that we can use to identify the language used for the visual part of the page, while using the non-UI material for the culture Such as date and number formatting, sorting and so on. In many situations, you want to use the same culture and uicultures, but in cases where you want to separate these two, for example when you want to localize the text of a website, while still one Output the relevant date or number format, no matter where the user comes from.